import { _decorator, Component, Node, Label, Vec3, UITransform, tween } from 'cc';
import ViewBase from '../../engine/ViewBase';
const { ccclass, property } = _decorator;

@ccclass('ViewTip')
export class ViewTip extends ViewBase {

    private static tipCount: number = 0;
    private lbTip: Label;
    private bg: Node
    private tipMsg: string = "";

    private pos: Vec3 = new Vec3(0, 200, 0);
    private pianYiY: number = 200;

    onInitChild(tipMsg: string) {
        this.tipMsg = tipMsg;
        ViewTip.tipCount++;
        this.node.setPosition(0, this.pianYiY)
    }

    onEnable() {
        super.onEnable();
        this.setTopUI()
        this.bg = this.getChild(this.node, "bg")
        this.lbTip = this.getChild(this.node, "lbTip", Label);
        this.lbTip.string = this.tipMsg;
        this.scheduleOnce(() => {
            this.bg.getComponent(UITransform).width = this.lbTip.getComponent(UITransform).width + 30
            this.bg.getComponent(UITransform).height = this.lbTip.getComponent(UITransform).height + 30
        })
        tween(this.node).delay(1).by(1, { position: this.pos }).call(() => {
            this.closeView();
        }).start()
    }

    onDisable() {
        ViewTip.tipCount--;
    }

}

